/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package qltv;

import Controller.ChiTietPhieuMuonController;
import Controller.ChiTietPhieuTraController;
import Controller.DocGiaController;
import Controller.NgonNguController;
import Controller.NhaXuatBanController;
import Controller.PhieuTraController;
import Controller.SachController;
import Controller.TacGiaController;
import Controller.TheLoaiController;
import Controller.tmpTaoPhieuTraController;
import DataAccess.ChiTietPhieuMuon;
import DataAccess.ChiTietPhieuTra;
import DataAccess.DocGia;
import DataAccess.PhieuTra;
import DataAccess.Sach;
import DataAccess.TmpTaoPhieuTra;
import java.awt.TextField;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author My PC
 */
public class TraSachform extends javax.swing.JFrame implements IKiemTra{

    /**
     * Creates new form RegisterTraSachform
     */
    PhieuTraController objControl=new PhieuTraController();
    DocGiaController dgControl=new DocGiaController();
    ChiTietPhieuMuonController ctpmControl=new ChiTietPhieuMuonController();
    ChiTietPhieuTraController ctptControl=new ChiTietPhieuTraController();
    SachController sachControl=new SachController();
    TacGiaController tgControl=new TacGiaController();
    NhaXuatBanController nxbControl=new NhaXuatBanController();
    TheLoaiController tlControl=new TheLoaiController();
    NgonNguController nnControl=new NgonNguController();
    int chon,lastID;
    Date d;
    List<ChiTietPhieuMuon> lstCT=null;
    public TraSachform() {
        initComponents();
        lstKT=new ArrayList<IKiemTra>();
        lastID=objControl.GetLastID()+1;
        txtPhieuTraID.setText(String.valueOf(lastID));
        d = new Date(System.currentTimeMillis());
        String s=d.toString();
        txtNgayTra.setText(s);
//        cbxTinhTrang.addItem("Bình thường");
//        cbxTinhTrang.addItem("Hỏng");
//        cbxTinhTrang.addItem("Mất");
        _txtSachID=txtTaiLieuID;
        _ngayhentra=labNgayHenTra;
    }
ArrayList<IKiemTra> lstKT;
Sach s;
Date ngayhentra;
    @Override
    public void Update(ChiTietPhieuMuon ctpm,Date ngayhentra)
    {
        txtTaiLieuID.setText(String.valueOf(ctpm.getSachId()));
        this.ngayhentra=ngayhentra;
        s=sachControl.GetObjByID(ctpm.getSachId(), "Sach");
        labTenTaiLieu.setText(s.getTenSach());
        labTacGia.setText(tgControl.GetObjByID(s.getTacGiaId(), "TacGia").getTenTacGia());
        labNXB.setText(nxbControl.GetObjByID(s.getNhaXuatBanId(), "NhaXuatBan").getTenNhaXuatBan());
        labTheLoai.setText(tlControl.GetObjByID(s.getTheLoaiId(), "TheLoai").getTenTheLoai());
        labNgonNgu.setText(nnControl.GetObjByID(s.getNamXuatBan(), "NgonNgu").getTenNgonNgu());
//        labSoLuong.setText(String.valueOf(s.getSoSach()));
        
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtPhieuTraID = new javax.swing.JTextField();
        txtNgayTra = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        txtDocGiaID = new javax.swing.JTextField();
        lbChucDanh = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        lbTenDocGia = new javax.swing.JLabel();
        lbDonVi = new javax.swing.JLabel();
        lbEmail = new javax.swing.JLabel();
        lbNgayHetHan = new javax.swing.JLabel();
        lbNgayLamThe = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        txtTaiLieuID = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        lbTenTaiLieu = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        lbNgayHenTra = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        labTenTaiLieu = new javax.swing.JLabel();
        labTacGia = new javax.swing.JLabel();
        labNXB = new javax.swing.JLabel();
        labTheLoai = new javax.swing.JLabel();
        labNgonNgu = new javax.swing.JLabel();
        labNgayHenTra = new javax.swing.JLabel();
        cbxTinhTrang = new javax.swing.JComboBox();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        btnChon = new javax.swing.JButton();
        btnTraSach = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMaximumSize(new java.awt.Dimension(947, 947));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Thông tin phiếu trả"));

        jLabel1.setText("Mã phiếu trả : ");

        jLabel2.setText("Ngày trả : ");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtPhieuTraID, javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE)
                    .addComponent(txtNgayTra, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(txtPhieuTraID, javax.swing.GroupLayout.DEFAULT_SIZE, 29, Short.MAX_VALUE))
                .addGap(11, 11, 11)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtNgayTra, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(110, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Thông tin độc giả"));

        jLabel4.setText("Mã thẻ thư viện :");

        lbChucDanh.setText("Chức danh :   ");

        jButton1.setText("Kiểm tra");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        lbTenDocGia.setText("Tên độc giả :   ");

        lbDonVi.setText("Đơn vị :   ");

        lbEmail.setText("Email : ");

        lbNgayHetHan.setText("Ngày hết hạn : ");

        lbNgayLamThe.setText("Ngày làm thẻ :  ");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lbNgayHetHan, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lbTenDocGia, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtDocGiaID, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(lbChucDanh, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lbDonVi, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(lbNgayLamThe, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lbEmail, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 376, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(195, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(txtDocGiaID))
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 29, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lbTenDocGia, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbChucDanh, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbDonVi, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(3, 3, 3)
                .addComponent(lbNgayLamThe, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbNgayHetHan, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Thông tin tài liệu"));
        jPanel3.setPreferredSize(new java.awt.Dimension(355, 320));

        jLabel5.setText("Mã tài liệu : ");

        jButton2.setText("Chọn");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        lbTenTaiLieu.setText("Tên Tài Liệu : ");

        jLabel7.setText("Tác Giả : ");

        jLabel8.setText("Thể loại : ");

        jLabel9.setText("Ngôn ngữ : ");

        jLabel11.setText("Nhà xuất bản : ");

        lbNgayHenTra.setText("Ngày hẹn trả : ");

        jLabel3.setText("Tình trạng sách : ");

        cbxTinhTrang.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "bình thường", "hỏng", "mất" }));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(txtTaiLieuID, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(cbxTinhTrang, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(labTheLoai, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(lbTenTaiLieu, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(labTacGia, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)
                                    .addComponent(labNXB, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(labTenTaiLieu, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(jPanel3Layout.createSequentialGroup()
                                    .addComponent(lbNgayHenTra)
                                    .addGap(18, 18, 18)
                                    .addComponent(labNgayHenTra, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
                                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(labNgonNgu, javax.swing.GroupLayout.PREFERRED_SIZE, 224, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(0, 12, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton2))))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtTaiLieuID)
                    .addComponent(jButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbTenTaiLieu, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labTenTaiLieu, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labTacGia, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labNXB, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labTheLoai, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labNgonNgu, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbNgayHenTra, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labNgayHenTra, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(cbxTinhTrang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Danh sách tài liệu"));

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Mã tài liệu", "Tên tài liệu", "Số ngày quá hạn", "Tiền đền"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.Integer.class, java.lang.Object.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 561, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE)
        );

        btnChon.setText("Chọn sách");
        btnChon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnChonActionPerformed(evt);
            }
        });

        btnTraSach.setText("Trả sách");
        btnTraSach.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTraSachActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        jLabel6.setText("TRẢ SÁCH");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 357, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(btnChon)
                        .addGap(37, 37, 37)
                        .addComponent(btnTraSach, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(66, 66, 66)))
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(26, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 232, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 317, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnTraSach, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnChon, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(27, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        try
        {
        DocGia dg=dgControl.GetObjByID(Integer.parseInt(txtDocGiaID.getText()),"DocGia");
        lbTenDocGia.setText(lbTenDocGia.getText()+dg.getTenDocGia() );
        lbChucDanh.setText(lbChucDanh.getText()+dg.getNgheNghiep());
        lbDonVi.setText(lbDonVi.getText()+dg.getDonVi());
        lbEmail.setText(lbEmail.getText()+dg.getEmail());
        lstCT=ctpmControl.GetCTPMByDocGia(dg.getDocGiaId());
        KiemTraform ktForm=new KiemTraform(dg,lstCT);
        ktForm.show();
        }
        catch(Exception ex)
        {
            JOptionPane.showConfirmDialog(null, " Khong co ma doc gia nay","Thông báo",JOptionPane.OK_OPTION);
        }
    }//GEN-LAST:event_jButton1ActionPerformed
DefaultTableModel model;
tmpTaoPhieuTraController tptControl=new tmpTaoPhieuTraController();
    private void btnTraSachActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTraSachActionPerformed
        // TODO add your handling code here:
        PhieuTra phieutra=new PhieuTra();
        
        phieutra.setDocGiaId(Integer.parseInt(txtDocGiaID.getText()));
        phieutra.setPhieuTraId(Integer.parseInt(txtPhieuTraID.getText()));
        phieutra.setNgayTra(d);
        objControl.Insert(phieutra);
        
        for(int i=0;i<model.getColumnCount();i++)
        {
            ChiTietPhieuTra ctpt=new ChiTietPhieuTra();
            ctpt.setCtptid(ctptControl.GetLastID()+1);
            ctpt.setPhieuTraId(Integer.parseInt(txtPhieuTraID.getText()));
            ctpt.setSachId(s.getSachId());
            ctpt.setTinhTrangSach(cbxTinhTrang.getSelectedItem().toString());
            
            TmpTaoPhieuTra tmp=new TmpTaoPhieuTra();
            
            Sach s=sachControl.GetObjByID(ctpt.getSachId(), "Sach");
            sachControl.UpdateSoLuong(ctpt.getSachId(), s.getSoSach()+1);
            
            tmp.setDocGiaId(phieutra.getDocGiaId());
            tmp.setPhieuTraId(phieutra.getPhieuTraId());
            tmp.setSachId(ctpt.getSachId());
            tmp.setTenDocGia(dgControl.GetObjByID(phieutra.getDocGiaId(), "DocGia").getTenDocGia());
            tmp.setTenSach(sachControl.GetObjByID(ctpt.getSachId(), "Sach").getTenSach());
            tmp.setTinhTrangSach(ctpt.getTinhTrangSach());
            tptControl.Insert(tmp);
            
        }
            int click=JOptionPane.showConfirmDialog(null, " Bạn có muốn in phiếu trả không ?","Thông báo",JOptionPane.YES_NO_OPTION);
        if(click==JOptionPane.YES_OPTION)
        {
            try { 
            String reportName = "E:\\hoctap\\ky 8\\Java\\QLTV\\src\\report\\InPhieuTra.jrxml"; 
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            String database="jdbc:sqlserver://MyPC:1433;databaseName=QLTV";
            String us="sa";
            String pass="sa";
            Connection conn=(Connection)DriverManager.getConnection(database,us,pass);
            HashMap map = new HashMap(); 
            InputStream is = this.getClass().getClassLoader().getResourceAsStream(reportName); 
            JasperReport jr=JasperCompileManager.compileReport(reportName);
            JasperPrint jasperPrint = JasperFillManager.fillReport(jr, map, conn); 
            //     JasperExportManager.exportReportToHtmlFile(jasperPrint, "huy.html"); 

         //   JasperViewer jv = new JasperViewer(jasperPrint, false); 
            JasperViewer.viewReport(jasperPrint);
          //  jv.setVisible(true); 
        } catch (Exception ex) { 
            System.out.println(ex.getMessage()); 
        } 
        }  
    }//GEN-LAST:event_btnTraSachActionPerformed

    private void btnChonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnChonActionPerformed
        // TODO add your handling code here:
        Sach s=new Sach();
//        s.setSachId(Integer.parseInt(txtTaiLieuID.getText()));
//        s.setTenSach(labTenTaiLieu.getText());
//        s.s
         model = (DefaultTableModel) jTable1.getModel();
         long ngayquahan=(d.getTime()-ngayhentra.getTime())/(60*60*1000*24);
         float tienden=(float)ngayquahan*1000;
         model.addRow(new Object[]{s.getSachId(), s.getTenSach(), ngayquahan,tienden});
    }//GEN-LAST:event_btnChonActionPerformed
static int _masach;
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        DocGia dg=dgControl.GetObjByID(Integer.parseInt(txtDocGiaID.getText()),"DocGia");
        lstCT=ctpmControl.GetCTPMByDocGia(dg.getDocGiaId());
        KiemTraform ktForm=new KiemTraform(dg,lstCT);
        ktForm.show();
//        Sach obj=sachControl.GetObjByID(_masach, "Sach");
//        labTenTaiLieu.setText(obj.getTenSach());
//        labTacGia.setText(String.valueOf(obj.getTacGiaId()));
//        labNXB.setText(String.valueOf(obj.getNhaXuatBanId()));
//        labTheLoai.setText(String.valueOf(obj.getTheLoaiId()));
//        labNgonNgu.setText(String.valueOf(obj.getNgonNguId()));
   //     labSoLuong.sett
    }//GEN-LAST:event_jButton2ActionPerformed
 static JTextField _txtSachID;
 static JLabel _ngayhentra,_tentailieu,_tacgia,_nxb,_theloai,_nn;
    public static void chonSach(Sach _s,Date ngayhentra)
    {
        _txtSachID.setText(String.valueOf(_s.getSachId()));
        _ngayhentra.setText(String.valueOf(ngayhentra));
        _tentailieu.setText(_s.getTenSach());
        _tacgia.setText(String.valueOf(_s.getTacGiaId()));
        _nxb.setText(String.valueOf(_s.getNhaXuatBanId()));
        _theloai.setText(String.valueOf(_s.getTheLoaiId()));
        _nn.setText(String.valueOf(_s.getNgonNguId()));
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TraSachform.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TraSachform.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TraSachform.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TraSachform.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TraSachform().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnChon;
    private javax.swing.JButton btnTraSach;
    private javax.swing.JComboBox cbxTinhTrang;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JLabel labNXB;
    private javax.swing.JLabel labNgayHenTra;
    private javax.swing.JLabel labNgonNgu;
    private javax.swing.JLabel labTacGia;
    private javax.swing.JLabel labTenTaiLieu;
    private javax.swing.JLabel labTheLoai;
    private javax.swing.JLabel lbChucDanh;
    private javax.swing.JLabel lbDonVi;
    private javax.swing.JLabel lbEmail;
    private javax.swing.JLabel lbNgayHenTra;
    private javax.swing.JLabel lbNgayHetHan;
    private javax.swing.JLabel lbNgayLamThe;
    private javax.swing.JLabel lbTenDocGia;
    private javax.swing.JLabel lbTenTaiLieu;
    private javax.swing.JTextField txtDocGiaID;
    private javax.swing.JTextField txtNgayTra;
    private javax.swing.JTextField txtPhieuTraID;
    private javax.swing.JTextField txtTaiLieuID;
    // End of variables declaration//GEN-END:variables

}
